{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "aggressive-freeware",
   "metadata": {},
   "source": [
    "https://leetcode.com/problems/most-profit-assigning-work\n",
    "\n",
    "\n",
    "Time Limit Exceeded\n",
    "\n",
    "\n",
    "```go\n",
    "package main\n",
    "\n",
    "import (\n",
    "\t\"fmt\"\n",
    "\t\"sort\"\n",
    ")\n",
    "\n",
    "func binary_search(arr []int, low int, high int, x int) int {\n",
    "\tif high >= low {\n",
    "\t\tmid := (high + low) / 2\n",
    "\t\tif arr[mid] == x {\n",
    "\t\t\tfor mid+1 < len(arr) {\n",
    "\t\t\t\tif arr[mid+1] > x {\n",
    "\t\t\t\t\treturn mid\n",
    "\t\t\t\t}\n",
    "\t\t\t\tmid += 1\n",
    "\t\t\t}\n",
    "\t\t\treturn mid\n",
    "\t\t} else if arr[mid] > x {\n",
    "\t\t\treturn binary_search(arr, low, mid-1, x)\n",
    "\t\t} else {\n",
    "\t\t\treturn binary_search(arr, mid+1, high, x)\n",
    "\t\t}\n",
    "\t} else {\n",
    "\t\treturn high\n",
    "\t}\n",
    "}\n",
    "\n",
    "type info struct {\n",
    "\tindex_               int\n",
    "\tdifficulty_, profit_ int\n",
    "}\n",
    "\n",
    "func maxProfitAssignment(difficulty []int, profit []int, worker []int) int {\n",
    "\t//6:55\n",
    "\tvar info_arr = make([]info, 0)\n",
    "\tfor i, _ := range difficulty {\n",
    "\t\tinfo_arr = append(info_arr, info{\n",
    "\t\t\tindex_:      i,\n",
    "\t\t\tdifficulty_: difficulty[i],\n",
    "\t\t\tprofit_:     profit[i],\n",
    "\t\t})\n",
    "\t}\n",
    "\tsort.Slice(info_arr, func(i, j int) bool {\n",
    "\t\treturn info_arr[i].difficulty_ < info_arr[j].difficulty_\n",
    "\t})\n",
    "\tnew_difficulty := make([]int, 0)\n",
    "\tnew_profit := make([]int, 0)\n",
    "\tfor i, _ := range info_arr {\n",
    "\t\tnew_difficulty = append(new_difficulty, info_arr[i].difficulty_)\n",
    "\t\tnew_profit = append(new_profit, info_arr[i].profit_)\n",
    "\t}\n",
    "\n",
    "\tsort.Slice(worker[:], func(i, j int) bool {\n",
    "\t\treturn worker[i] < worker[j]\n",
    "\t})\n",
    "\tmoney := 0\n",
    "\tlength := len(difficulty)\n",
    "\ttemp_slice := make([]int, 0)\n",
    "\tfor _, wk := range worker {\n",
    "\t\tindex := binary_search(new_difficulty, 0, length-1, wk)\n",
    "        if index < 0 {\n",
    "\t\t\tcontinue\n",
    "\t\t}\n",
    "\t\tif new_difficulty[index] <= wk {\n",
    "\t\t\ttemp_slice = temp_slice[:0]\n",
    "\t\t\ttemp_slice = new_profit[:index+1]\n",
    "\t\t\tsort.Slice(temp_slice, func(i, j int) bool {\n",
    "\t\t\t\treturn temp_slice[i] < temp_slice[j]\n",
    "\t\t\t})\n",
    "\t\t\tmoney += temp_slice[len(temp_slice)-1]\n",
    "\t\t}\n",
    "\t}\n",
    "\treturn money\n",
    "    //7:28\n",
    "}\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "perfect-syntax",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Go",
   "language": "go",
   "name": "gophernotes"
  },
  "language_info": {
   "codemirror_mode": "",
   "file_extension": ".go",
   "mimetype": "",
   "name": "go",
   "nbconvert_exporter": "",
   "pygments_lexer": "",
   "version": "go1.15.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
